package com.auxgroup.hr.front.site.co.process;

import java.math.BigDecimal;
import java.util.Set;

import javax.annotation.Resource;

import com.auxgroup.hr.front.site.co.BaseWfCO;
import com.auxgroup.hr.front.site.inteceptor.SessionGain;
import com.auxgroup.hr.front.site.vo.process.WfTolHdrRespVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.auxgroup.hr.front.commons.BaseRetCode;
import com.auxgroup.hr.front.commons.vo.BaseResponseVO;
import com.auxgroup.hr.front.commons.vo.UserDTO;
import com.auxgroup.hr.front.dao.domain.JobCurrPrimary;
import com.auxgroup.hr.front.dao.domain.PsCAppStepInst;
import com.auxgroup.hr.front.dao.domain.PsCWfEmpVw;
import com.auxgroup.hr.front.dao.domain.PsCWfTolHdr;
import com.auxgroup.hr.front.dao.repository.PsCWfEmpVwRepository;
import com.auxgroup.hr.front.dozer.IObjectMapper;
import com.auxgroup.hr.front.service.comm.OprdefnService;
import com.auxgroup.hr.front.service.process.ProcessService;
import com.auxgroup.hr.front.service.process.WfFileService;
import com.auxgroup.hr.front.service.process.WfTolHdrService;
import com.auxgroup.hr.front.site.co.BaseCO;
import com.auxgroup.hr.front.site.inteceptor.SessionGain;
import com.auxgroup.hr.front.site.vo.process.WfTolHdrRespVO;

/**
 * 工作移交审批流程
 * @author wangchangyun
 * @version 创建时间：180601 
 */
@RestController
@RequestMapping("${auxgroup.hr.contextPath}/wfTolHdr")
public class WfTolHdrCO extends BaseWfCO {

	private static final Logger logger = LoggerFactory.getLogger(WfTolHdrCO.class);

	@Autowired
	public WfTolHdrService wfTolHdrService;

	

	@Autowired
	private PsCWfEmpVwRepository psCWfEmpVwRepository;
	
	@Resource(name = "dozerMapper")
	protected IObjectMapper objectMapper;

	
	/**
	 * 获取工作移交详情
	 * @return
	 */
	@GetMapping(value = "/getTolInfo")
	public BaseResponseVO getOne(String cTransactionNbr,@SessionGain("user") UserDTO user) {
		logger.info("getWfDmcHdr param= {}", cTransactionNbr);
		PsCWfTolHdr wfTolHdr = wfTolHdrService.getWfTolHdr(cTransactionNbr);
		if (wfTolHdr == null) {
			return buildRespone(BaseRetCode.CODE_ERROR_PROCESS_NOT_EXIST);
		}
		WfTolHdrRespVO respVo = objectMapper.map(wfTolHdr, WfTolHdrRespVO.class);
		JobCurrPrimary primary = new JobCurrPrimary();
		primary.setEmplid(user.getEmplId());
		primary.setEmplRcd(new BigDecimal(0));
		PsCWfEmpVw emp = psCWfEmpVwRepository.findOne(primary);//获取个人信息内容
		if(emp!=null){
			respVo.setcWfName(emp.getNameDisplay());
			respVo.setcWfJcDescr(emp.getJobcodeDescr());
			respVo.setcWfDeptdescr(emp.getDeptDescr());
			respVo.setcWfPhone(emp.getPhone());
		}
		fillBaseWfInfo(user, wfTolHdr, respVo);
		return buildRespone(respVo);
	}

	@Override
	protected Set<String> getAuthFileds() {
		return null;
	}
}
